using UnityEngine;

public class WaveTriggerController : SynchronizedGameObject
{
	[SerializeField]
	private OnChargeWave onChargeWave;

	[SerializeField]
	private Collider hideChargeTrigger;

	private new void Awake()
	{
		if (hideChargeTrigger == null)
		{
			hideChargeTrigger = base.gameObject.GetComponent<Collider>();
		}
	}

	public void OnTriggerEnter(Collider other)
	{
		if (!base.isMine)
		{
			return;
		}
		Mortal componentInParent = other.gameObject.GetComponentInParent<Mortal>();
		if ((bool)componentInParent && TDMController.isTeamGameType && base.photonView.isMine)
		{
			if (componentInParent is EntityBehavior)
			{
				EntityBehavior entityBehavior = componentInParent as EntityBehavior;
				PlayerBehavior playerBehavior = entityBehavior.getMainHuman() as PlayerBehavior;
				PlayerBehavior playerBehavior2 = GameController.instance.FindPlayer(entityBehavior.photonView.ownerId);
				if ((entityBehavior.getMainHuman() != null && playerBehavior != null && playerBehavior.localTeam == TDMController.myTeam && !entityBehavior.isMine) || (entityBehavior.privateCar && playerBehavior2 != null && playerBehavior2.localTeam == TDMController.myTeam))
				{
					return;
				}
			}
			else if (componentInParent is PlayerBehavior)
			{
				PlayerBehavior playerBehavior3 = componentInParent as PlayerBehavior;
				if (playerBehavior3.localTeam == TDMController.myTeam && !playerBehavior3.isMine)
				{
					return;
				}
			}
		}
		if (other.gameObject.tag != "Weapon" && other.gameObject.layer == 0)
		{
			if (settings.offlineMode)
			{
				onChargeWave.Hide();
			}
			else
			{
				onChargeWave.photonView.RPC("Hide", PhotonTargets.All);
			}
		}
		else if (componentInParent is EntityBehavior || componentInParent is CRGate)
		{
			if (settings.offlineMode)
			{
				onChargeWave.Hide();
			}
			else
			{
				onChargeWave.photonView.RPC("Hide", PhotonTargets.All);
			}
		}
		else
		{
			Invoke("Destroy", 10f);
		}
	}

	public void Hide()
	{
		if (hideChargeTrigger != null)
		{
			hideChargeTrigger.enabled = false;
		}
	}

	private void Destroy()
	{
		if (settings.offlineMode)
		{
			Object.Destroy(base.gameObject);
		}
		else
		{
			PhotonNetwork.Destroy(base.gameObject);
		}
	}
}
